/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ihale;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import org.ihale.database.DatabaseEmre;
import org.ihale.database.DatabaseYakup;
import org.ihale.satinalmaci.SatinAlmaci;
import org.ihale.tedarikci.Tedarikci;
import org.ihale.yonetici.Admin;
import org.ihale.yonetici.AdminBean;
/**
 *
 * @author yakup
 */
@ManagedBean(name = "kalemBean")
@SessionScoped
public class KalemBean {
 
    public KalemBean() {
    }

    public int getFoo() {
        return foo;
    }

    public void setFoo(int foo) {
        this.foo = foo;
    }

    private int foo;
    
   
    private List<Kalem> kalemListesi = new LinkedList<Kalem>();

    public List<Kalem> getKalemListesi() {
        return kalemListesi;
    }

    public void setKalemListesi(List<Kalem> kalemListesi) {
        this.kalemListesi = kalemListesi;
    }

    public void guncelleKalemListesi() throws FileNotFoundException {
        try {
            AdminBean adminBean = new AdminBean();
            adminBean = (AdminBean) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("adminBean");
            DatabaseYakup dby = new DatabaseYakup();
            dby.connect();
            kalemListesi = dby.getirIhaleKalemBilgileri(adminBean.getSeciliIhale());
            dby.disconnect();
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(KalemBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(KalemBean.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
    
    public void deneme(){
        System.out.println("oldu uuuu");
    }
    
    public void guncelleKalemBilgileri(){
        try {
            DatabaseYakup dby = new DatabaseYakup();
            dby.connect();
            dby.guncelleKalemBilgileri(kalemListesi);
            dby.disconnect();
             FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Kalem Bilgileri Başarıyla Güncellendi! "));
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(KalemBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
             FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Kalem bilgisi güncellenemedi! "));
            Logger.getLogger(KalemBean.class.getName()).log(Level.SEVERE, null, ex);
        }
    
    }
}
